
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/05/21
// Design Name:
// Module Name: sr_addr_match
// Project Name: wujian100
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////
module iopmp_apb0addr_match #
(
    `include "apb0_params.v"
)
(
    input      [31:0]            addrmt_haddr_i,
    input      [31:0]            addrmt_prireg_i,

    output reg [1:0]             addrmt_pri_o,
    output     [15:0]            addrmt_hit_o
);

localparam ADDR_MASK_1K  = 32'hFFFF_FC00; // 0000_03FF取反
localparam ADDR_MASK_4K  = 32'hFFFF_F000; // 0000_0FFF取反
localparam ADDR_MASK_16K = 32'hFFFF_C000; // 0000_3FFF取反

wire [15:0]    addr_hit;

assign addr_hit[0]  = ((addrmt_haddr_i & ADDR_MASK_1K)  == APB_LEAF_SLV0_START_ADDR);
assign addr_hit[1]  = ((addrmt_haddr_i & ADDR_MASK_1K)  == APB_LEAF_SLV1_START_ADDR);
assign addr_hit[2]  = ((addrmt_haddr_i & ADDR_MASK_1K)  == APB_LEAF_SLV2_START_ADDR);
assign addr_hit[3]  = ((addrmt_haddr_i & ADDR_MASK_1K)  == APB_LEAF_SLV3_START_ADDR);
assign addr_hit[4]  = ((addrmt_haddr_i & ADDR_MASK_4K)  == APB_LEAF_SLV4_START_ADDR);
assign addr_hit[5]  = ((addrmt_haddr_i & ADDR_MASK_4K)  == APB_LEAF_SLV5_START_ADDR);
assign addr_hit[6]  = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV6_START_ADDR);
assign addr_hit[7]  = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV7_START_ADDR);
assign addr_hit[8]  = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV8_START_ADDR);
assign addr_hit[9]  = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV9_START_ADDR);
assign addr_hit[10] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV10_START_ADDR);
assign addr_hit[11] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV11_START_ADDR);
assign addr_hit[12] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV12_START_ADDR);
assign addr_hit[13] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV13_START_ADDR);
assign addr_hit[14] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV14_START_ADDR);
assign addr_hit[15] = ((addrmt_haddr_i & ADDR_MASK_16K) == APB_LEAF_SLV15_START_ADDR);

assign addrmt_hit_o = addr_hit;
always @(*) begin
    case (1'b1)
         addr_hit[0] : addrmt_pri_o = addrmt_prireg_i[1:0];
         addr_hit[1] : addrmt_pri_o = addrmt_prireg_i[3:2];
         addr_hit[2] : addrmt_pri_o = addrmt_prireg_i[5:4];
         addr_hit[3] : addrmt_pri_o = addrmt_prireg_i[7:6];
         addr_hit[4] : addrmt_pri_o = addrmt_prireg_i[9:8];
         addr_hit[5] : addrmt_pri_o = addrmt_prireg_i[11:10];
         addr_hit[6] : addrmt_pri_o = addrmt_prireg_i[13:12];
         addr_hit[7] : addrmt_pri_o = addrmt_prireg_i[15:14];
         addr_hit[8] : addrmt_pri_o = addrmt_prireg_i[17:16];
         addr_hit[9] : addrmt_pri_o = addrmt_prireg_i[19:18];
         addr_hit[10]: addrmt_pri_o = addrmt_prireg_i[21:20];
         addr_hit[11]: addrmt_pri_o = addrmt_prireg_i[23:22];
         addr_hit[12]: addrmt_pri_o = addrmt_prireg_i[25:24];
         addr_hit[13]: addrmt_pri_o = addrmt_prireg_i[27:26];
         addr_hit[14]: addrmt_pri_o = addrmt_prireg_i[29:28];
         addr_hit[15]: addrmt_pri_o = addrmt_prireg_i[31:30];
        default: addrmt_pri_o = 2'b11;
    endcase

    
end


endmodule
